<!DOCTYPE html>
<html>
<head>
	<title>todoList</title>
	<script type="text/javascript" src="./vue.js"></script>
</head>
<body>	
	<div id="app">
		<input  type="text" v-model="inputValue">
		<button v-on:click="btnHandler">提交</button>
		<ul>
			<todo-list @delete="deleteItem" :index="index" :content="item" v-for="(item,index) in list"></todo-list>
		</ul>
	</div>
	<script>

		// 定义全局组件
		// Vue.component("TodoList" , {
		// 	props : ["content"] ,
		// 	template : "<li>{{content}}</li>"
		// });

		// 定义局部组件
		var todoList = {
			props : ["content" , "index"] ,
			template : "<li @click='itemHandler'>{{content}}</li>" ,
			methods : {
				itemHandler : function() {
					this.$emit('delete' , this.index)
				}
			}
		};

		var app = new Vue({
			el : '#app' ,
			data : {
				list : [],
				inputValue : ''
			},
			methods : {
				btnHandler : function() {
					this.list.push(this.inputValue)
					this.inputValue = ''
				},
				deleteItem : function(index) {
					this.list.splice(index , 1)
				}
			},
			components : {
				TodoList : todoList
			}
		});
	</script>
</body>
</html>